/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.login.plugin.login.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputFilter.LengthFilter;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import com.qihoo.gamecenter.sdk.common.i.q;
import com.qihoo.gamecenter.sdk.common.view.CustButton;
import com.qihoo.gamecenter.sdk.common.view.CustEditText;
import com.qihoo.gamecenter.sdk.login.plugin.d.a;
import com.qihoo.gamecenter.sdk.login.plugin.h.c;
import com.qihoo.gamecenter.sdk.login.plugin.h.k;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONObject;

public class SetPasswordDialog extends RelativeLayout implements d {
    private com.qihoo.gamecenter.sdk.login.plugin.f.a a;
    private Activity b;
    private String c;
    private Intent d;
    private f e;
    private RelativeLayout f;
    private TextView g;
    private CustButton h;
    private TextView i;
    private CustEditText j;
    private View k;
    private String l = null;
    private String m = null;
    private ManualLoginProgress n;
    private static String[] o = {
            String.format(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.am), new Object[] { Integer.valueOf(20) }),
            String.format(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.al), new Object[] { Integer.valueOf(6) }) };
    private Handler p = new a(this);
    private View.OnClickListener q = new View.OnClickListener() {
        public void onClick(View paramView) {
            if (SetPasswordDialog.f(SetPasswordDialog.this) != paramView)
                return;
            SetPasswordDialog.b(SetPasswordDialog.this);
        }
    };

    public SetPasswordDialog(Activity paramActivity, String paramString, Intent paramIntent, f paramf) {
        super(paramActivity);
        this.b = paramActivity;
        this.c = paramString;
        this.d = paramIntent;
        this.e = paramf;
        this.a = com.qihoo.gamecenter.sdk.login.plugin.f.a.a(this.b);
        d();
    }

    public void setManualLoginProgress(ManualLoginProgress paramManualLoginProgress) {
        this.n = paramManualLoginProgress;
    }

    private void d() {
        setBackgroundDrawable(this.a.a(-1073741797));
        setLayoutParams(new RelativeLayout.LayoutParams(com.qihoo.gamecenter.sdk.login.plugin.h.f.a(this.b, 320.0F), -2));
        setGravity(17);
        a(this.b);
    }

    private void a(Context paramContext) {
        int i1 = com.qihoo.gamecenter.sdk.login.plugin.h.f.a(paramContext, 16.0F);
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-1, -2);
        localLayoutParams.leftMargin = i1;
        localLayoutParams.rightMargin = i1;
        localLayoutParams.topMargin = i1;
        localLayoutParams.bottomMargin = i1;
        this.f = new RelativeLayout(paramContext);
        this.f.setLayoutParams(localLayoutParams);
        addView(this.f);
        this.f.addView(b(paramContext));
        this.f.addView(c(paramContext));
        this.f.addView(d(paramContext));
        this.f.addView(e(paramContext));
        this.f.addView(f(paramContext));
        this.f.addView(g(paramContext));
    }

    private TextView b(Context paramContext) {
        TextView localTextView = new TextView(paramContext);
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-2, -2);
        localLayoutParams.addRule(14, -1);
        localTextView.setLayoutParams(localLayoutParams);
        localTextView.setId(e.B.ordinal());
        localTextView.setGravity(17);
        localTextView.setTextSize(1, c.g);
        localTextView.setTextColor(Color.parseColor("#FF7F16"));
        TextPaint localTextPaint = localTextView.getPaint();
        localTextPaint.setFakeBoldText(true);
        localTextView.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.ax));
        localTextView.setCompoundDrawablePadding(com.qihoo.gamecenter.sdk.login.plugin.h.f.a(paramContext, 5.0F));
        this.a.a(localTextView, 1073741874, 0, 0, 0);
        return localTextView;
    }

    private TextView c(Context paramContext) {
        this.g = new TextView(paramContext);
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-1, -2);
        localLayoutParams.topMargin = com.qihoo.gamecenter.sdk.login.plugin.h.f.a(paramContext, 16.0F);
        localLayoutParams.addRule(3, e.B.ordinal());
        this.g.setLayoutParams(localLayoutParams);
        this.g.setId(e.C.ordinal());
        this.g.setGravity(16);
        this.g.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.x));
        this.g.setTextColor(-16777216);
        return this.g;
    }

    private TextView d(Context paramContext) {
        this.i = new TextView(paramContext);
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-1, -2);
        localLayoutParams.topMargin = com.qihoo.gamecenter.sdk.login.plugin.h.f.a(paramContext, 16.0F);
        localLayoutParams.addRule(3, e.C.ordinal());
        this.i.setLayoutParams(localLayoutParams);
        this.i.setId(e.D.ordinal());
        this.i.setGravity(16);
        this.i.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.y));
        this.i.setTextColor(-16777216);
        return this.i;
    }

    private TextView e(Context paramContext) {
        TextView localTextView = new TextView(paramContext);
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-1, -2);
        localLayoutParams.topMargin = com.qihoo.gamecenter.sdk.login.plugin.h.f.a(paramContext, 16.0F);
        localLayoutParams.bottomMargin = com.qihoo.gamecenter.sdk.login.plugin.h.f.a(paramContext, 8.0F);
        localLayoutParams.addRule(3, e.D.ordinal());
        localTextView.setLayoutParams(localLayoutParams);
        localTextView.setId(e.E.ordinal());
        localTextView.setGravity(16);
        localTextView.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.z));
        localTextView.setTextColor(Color.parseColor("#666666"));
        return localTextView;
    }

    private LinearLayout f(Context paramContext) {
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-1,
                com.qihoo.gamecenter.sdk.login.plugin.h.f.a(paramContext, 47.0F));
        localLayoutParams.addRule(3, e.E.ordinal());
        LinearLayout localLinearLayout = new LinearLayout(paramContext);
        localLinearLayout.setLayoutParams(localLayoutParams);
        localLinearLayout.setId(e.F.ordinal());
        LinearLayout.LayoutParams localLayoutParams1 = new LinearLayout.LayoutParams(0, -2);
        localLayoutParams1.weight = 1.0F;
        LinearLayout.LayoutParams localLayoutParams2 = new LinearLayout.LayoutParams(-2, -2);
        localLinearLayout.setOrientation(0);
        this.a.a(localLinearLayout, -1073741801);
        localLinearLayout.setPadding(com.qihoo.gamecenter.sdk.login.plugin.h.f.a(paramContext, 5.0F), 0,
                com.qihoo.gamecenter.sdk.login.plugin.h.f.a(paramContext, 8.0F), 0);
        localLinearLayout.setGravity(16);
        TextView localTextView = new TextView(paramContext);
        localTextView.setTextColor(-16777216);
        localTextView.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.k));
        localTextView.setTextSize(1, c.h);
        localLinearLayout.addView(localTextView, localLayoutParams2);
        this.j = new CustEditText(paramContext);
        this.j.setTextColor(-16777216);
        this.j.setSingleLine(true);
        this.j.setHintTextColor(-3355444);
        this.j.setHint(String.format(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.ah),
                new Object[] { Integer.valueOf(6), Integer.valueOf(20) }));
        this.j.setTextSize(1, c.h);
        this.j.setBackgroundColor(0);
        this.j.setInputType(129);
        this.j.setPadding(com.qihoo.gamecenter.sdk.login.plugin.h.f.a(this.b, 10.0F), 0, 0, 0);
        this.j.setImeOptions(6);
        this.j.e();
        this.j.f();
        this.j.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            public boolean onEditorAction(TextView paramTextView, int paramInt, KeyEvent paramKeyEvent) {
                if ((((paramInt == 6) || (paramInt == 0)))
                        && (!(TextUtils.isEmpty(SetPasswordDialog.a(SetPasswordDialog.this).getText().toString()))))
                    SetPasswordDialog.b(SetPasswordDialog.this);
                return false;
            }
        });
        this.j.c();
        this.j.d();
        this.j.setOnFocusChangeListener(new View.OnFocusChangeListener(paramContext) {
            public void onFocusChange(View paramView, boolean paramBoolean) {
                if (!(paramBoolean))
                    return;
                SetPasswordDialog.c(SetPasswordDialog.this).getWindow().setSoftInputMode(4);
                InputMethodManager localInputMethodManager = (InputMethodManager) this.a
                        .getSystemService("input_method");
                if (localInputMethodManager == null)
                    return;
                localInputMethodManager.showSoftInput(SetPasswordDialog.a(SetPasswordDialog.this), 1);
            }
        });
        localLinearLayout.addView(this.j, localLayoutParams1);
        ImageView localImageView = new ImageView(paramContext);
        this.a.a(localImageView, 1073741835);
        localImageView.setVisibility(8);
        localImageView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View paramView) {
                SetPasswordDialog.a(SetPasswordDialog.this).setText("");
                SetPasswordDialog.d(SetPasswordDialog.this);
            }
        });
        localLinearLayout.addView(localImageView, new LinearLayout.LayoutParams(
                com.qihoo.gamecenter.sdk.login.plugin.h.f.a(paramContext, 20.0F),
                com.qihoo.gamecenter.sdk.login.plugin.h.f.a(paramContext, 20.0F)));
        InputFilter[] arrayOfInputFilter = { new InputFilter.LengthFilter(20) };
        this.j.setFilters(arrayOfInputFilter);
        this.j.a();
        this.j.b();
        this.j.addTextChangedListener(new TextWatcher(localImageView) {
            public void onTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3) {
                SetPasswordDialog.e(SetPasswordDialog.this).removeMessages(101);
                if (!(TextUtils.isEmpty(paramCharSequence))) {
                    Message localMessage = SetPasswordDialog.e(SetPasswordDialog.this).obtainMessage(101,
                            paramCharSequence);
                    SetPasswordDialog.e(SetPasswordDialog.this).sendMessage(localMessage);
                    this.a.setVisibility(0);
                    SetPasswordDialog.f(SetPasswordDialog.this).setText(
                            com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.az));
                }
                else {
                    this.a.setVisibility(8);
                    SetPasswordDialog.f(SetPasswordDialog.this).setText(
                            com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.ay));
                }
            }

            public void beforeTextChanged(CharSequence paramCharSequence, int paramInt1, int paramInt2, int paramInt3) {}

            public void afterTextChanged(Editable paramEditable) {
                if ((TextUtils.isEmpty(paramEditable))
                        || ((paramEditable.length() <= 20) && (paramEditable.length() >= 6))) {
                    SetPasswordDialog.e(SetPasswordDialog.this).removeMessages(101);
                    SetPasswordDialog.d(SetPasswordDialog.this);
                }
                if (TextUtils.isEmpty(paramEditable))
                    return;
                Editable localEditable = k.b(paramEditable);
                if (localEditable == null)
                    return;
                SetPasswordDialog.a(SetPasswordDialog.this).setText(localEditable);
                SetPasswordDialog.a(SetPasswordDialog.this).setSelection(localEditable.length());
            }
        });
        return localLinearLayout;
    }

    private LinearLayout g(Context paramContext) {
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-1, -2);
        localLayoutParams.addRule(3, e.F.ordinal());
        localLayoutParams.topMargin = com.qihoo.gamecenter.sdk.login.plugin.h.f.a(paramContext, 16.0F);
        LinearLayout localLinearLayout = new LinearLayout(paramContext);
        localLinearLayout.setLayoutParams(localLayoutParams);
        localLinearLayout.setOrientation(0);
        localLinearLayout.setGravity(17);
        this.h = new CustButton(paramContext);
        this.h.setId(e.j.ordinal());
        this.h.setLayoutParams(new LinearLayout.LayoutParams(-1, com.qihoo.gamecenter.sdk.login.plugin.h.f.a(this.b,
                47.0F)));
        this.h.setGravity(17);
        this.h.setTextColor(-1);
        this.h.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.ay));
        this.h.a();
        this.h.b();
        this.h.setOnClickListener(this.q);
        this.a.a(this.h, -1073741764, -1073741763, -1073741763);
        localLinearLayout.addView(this.h);
        return localLinearLayout;
    }

    private void a(String paramString) {
        if (this.k != null) {
            localObject = (TextView) this.k.findViewById(10001);
            ((TextView) localObject).setText(paramString);
            return;
        }
        Object localObject = new RelativeLayout(this.b);
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-2, -2);
        localLayoutParams.addRule(2, e.F.ordinal());
        this.f.addView((View) localObject, localLayoutParams);
        TextView localTextView = new TextView(this.b);
        localTextView.setId(10001);
        localTextView.setText(paramString);
        localTextView.setTextColor(Color.parseColor("#e46052"));
        this.a.a(localTextView, -1073741766);
        localTextView.setPadding(4, 0, 4, 0);
        localTextView.setTextSize(1, c.i);
        ((RelativeLayout) localObject).addView(localTextView, new RelativeLayout.LayoutParams(-2, -2));
        localTextView.setVisibility(4);
        localTextView.post(new Runnable(localTextView) {
            public void run() {
                this.a.setVisibility(0);
            }
        });
        this.k = ((View) localObject);
    }

    private void e() {
        if (this.k == null)
            return;
        this.f.removeView(this.k);
        this.k = null;
    }

    private void f() {
        if (!(com.qihoo.gamecenter.sdk.login.plugin.h.f.a(this.b, com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.c),
                this.c)))
            return;
        String str = this.j.getText().toString();
        if (!(TextUtils.isEmpty(str))) {
            if (str.length() < 6) {
                this.j.requestFocus();
                a(String.format(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.al), new Object[] { Integer.valueOf(6) }));
                return;
            }
            if (str.length() > 20) {
                this.j.requestFocus();
                a(String.format(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.am), new Object[] { Integer.valueOf(20) }));
                return;
            }
            if (k.c(str)) {
                this.j.requestFocus();
                a(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.ak));
                return;
            }
            com.qihoo.gamecenter.sdk.login.plugin.h.f.a(this.b);
            this.n.a(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.aB));
            new AsyncTask(str) {
                protected String a(Void[] paramArrayOfVoid) {
                    try {
                        String str = k
                                .a(SetPasswordDialog.c(SetPasswordDialog.this), SetPasswordDialog
                                        .g(SetPasswordDialog.this), SetPasswordDialog.h(SetPasswordDialog.this),
                                        this.a, com.qihoo.gamecenter.sdk.login.plugin.h.a.a(SetPasswordDialog
                                                .i(SetPasswordDialog.this)));
                        return com.qihoo.gamecenter.sdk.login.plugin.d.a.a(SetPasswordDialog.c(SetPasswordDialog.this),
                                str);
                    } catch (Exception localException) {}
                    return null;
                }

                protected void a(String paramString) {
                    SetPasswordDialog.j(SetPasswordDialog.this).a();
                    if (!(TextUtils.isEmpty(paramString))) {
                        try {
                            JSONObject localJSONObject = new JSONObject(paramString);
                            com.qihoo.gamecenter.sdk.login.plugin.h.e.a("SetPasswordDialog",
                                    new Object[] { "modify pwd----HttpServerAgent=" + localJSONObject });
                            int i = localJSONObject.getInt("errno");
                            String str = localJSONObject.optString("errmsg");
                            if (i == 0) {
                                HashMap localHashMap = new HashMap();
                                localHashMap.put("login_name", SetPasswordDialog.g(SetPasswordDialog.this));
                                localHashMap.put("login_pwd", this.a);
                                localHashMap.put("login_type", "4");
                                localHashMap.put("is_local_phone_account", "true");
                                SetPasswordDialog.k(SetPasswordDialog.this).a(2, localHashMap);
                            }
                            else {
                                SetPasswordDialog.a(SetPasswordDialog.this).setText("");
                                q.a(SetPasswordDialog.c(SetPasswordDialog.this),
                                        (TextUtils.isEmpty(str)) ? com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.aA)
                                                : str, 1, 80);
                            }
                        } catch (Exception localException) {
                            SetPasswordDialog.a(SetPasswordDialog.this).setText("");
                            q.a(SetPasswordDialog.c(SetPasswordDialog.this),
                                    com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.aA), 1, 80);
                        }
                    }
                    else {
                        SetPasswordDialog.a(SetPasswordDialog.this).setText("");
                        q.a(SetPasswordDialog.c(SetPasswordDialog.this),
                                com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.aA), 1, 80);
                    }
                }
            }.execute(new Void[0]);
        }
        else {
            com.qihoo.gamecenter.sdk.login.plugin.h.f.a(this.b);
            HashMap localHashMap = new HashMap();
            localHashMap.put("login_name", this.l);
            localHashMap.put("login_pwd", this.m);
            localHashMap.put("login_type", "4");
            localHashMap.put("is_local_phone_account", "true");
            this.e.a(2, localHashMap);
        }
    }

    public void a(Map paramMap) {
        com.qihoo.gamecenter.sdk.login.plugin.h.f.a(this.b);
        setVisibility(0);
        b(paramMap);
    }

    public void a() {
        setVisibility(8);
        if (this.n == null)
            return;
        this.n.a();
    }

    public void b(Map paramMap) {
        this.h.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.ay));
        e();
        this.g.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.x));
        this.i.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.y));
        this.l = null;
        this.m = null;
        if (paramMap == null)
            return;
        this.l = ((String) paramMap.get("mobile_phone_number"));
        this.m = ((String) paramMap.get("mobile_password"));
        if (this.l != null)
            this.g.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.x) + this.l);
        if (this.m == null)
            return;
        this.i.setText(com.qihoo.gamecenter.sdk.login.plugin.d.a(d.a.y) + this.m);
    }

    public void b() {
        setVisibility(0);
    }

    private static class a extends Handler {
        private SetPasswordDialog a;

        public a(SetPasswordDialog paramSetPasswordDialog) {
            this.a = paramSetPasswordDialog;
        }

        public void handleMessage(Message paramMessage) {
            if (paramMessage.what != 101)
                return;
            String str = String.valueOf(paramMessage.obj);
            int i = str.length();
            if (i > 20) {
                SetPasswordDialog.a(this.a, SetPasswordDialog.c()[0]);
            }
            else {
                if (i >= 6)
                    return;
                SetPasswordDialog.a(this.a, SetPasswordDialog.c()[1]);
            }
        }
    }
}